﻿using System;
using System.Windows.Controls;
using System.Windows;
using System.Windows.Media;

namespace CoTime.View.UserControls
{
    /// <summary>
    /// Interaction logic for UCTextBox.xaml
    /// </summary>
    public partial class UCTextBox : TextBox
    {
        #region [ Contructors ]

        public UCTextBox()
        {
            InitializeComponent();
            this.TextChanged += new TextChangedEventHandler(UCTextBox_TextChanged);
        }

        public UCTextBox(String name) : this()
        {
            this.Name = name;
        }

        #endregion

        #region [ UI Behavior ]

        void UCTextBox_TextChanged(object sender, TextChangedEventArgs e)
        {
            this.ToolTip = this.Text.Length * this.FontSize > this.Width ? this.Text : null;
        }

        #endregion

        #region [ Api ]

        private static readonly TextDecoration StrikethroughDecoration = new TextDecoration(
                                TextDecorationLocation.Strikethrough,
                                new Pen(Brushes.Black, 1),
                                -3,
                                TextDecorationUnit.Pixel,
                                TextDecorationUnit.Pixel
                            );

        public void Strikethrough()
        {
            this.Foreground = Brushes.Gray;
            this.TextDecorations = new TextDecorationCollection { StrikethroughDecoration };
        }

        public Boolean IsStrikethrough()
        {
            return this.TextDecorations != null && this.TextDecorations.Contains(StrikethroughDecoration);
        }

        #endregion
    }
}
